package LeetCodeSection;/*
 *
 *@author:    Xavier
 *@data:      2023 - 08 - 20
 *@time:      14:20
 *
 */


//1. 检查两颗树是否相同
// 相同的树
//https://leetcode.cn/problems/same-tree/
public class TheSameTree {
public class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {
      this.val = val;
      this.left = left;
      this.right = right;
    }
}

    class Solution {
        public boolean isSameTree(TreeNode p, TreeNode q) {
            if ((p == null && q != null) || (p != null && q == null)) {
                return false;
            }

            if (p == null && q == null) {
                return true;
            }

            if (p.val != q.val) {
                return false;
            }

            //左子树 和 右子树 都要去看 是否相等
            return isSameTree(p.left, q.left)
                    && isSameTree(p.right, q.right);

        }
    }
}
